/*
author:杨文超
email:yangwenchao@keynection.cn
*/
#pragma once

#include <inttypes.h>  // needs to be included for default system types (such as PRIxx)
#include "sdkconfig.h" // for KConfig options

#if __has_include("esp_idf_version.h")
#include "esp_idf_version.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
/* ----------------------- Defines ------------------------------------------*/
/*modbus_cfg Modbus Configuration
Most modules in the protocol stack are completly optional and can be
excluded. This is specially important if target resources are very small
and program memory space should be saved.
*/



#ifdef ESP_IDF_VERSION

#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0))
// Features supported from 4.4
#define MB_TIMER_SUPPORTS_ISR_DISPATCH_METHOD 1
#endif

#endif



#define MB_EVENT_QUEUE_SIZE                     ( 20 )
#define MB_EVENT_QUEUE_TIMEOUT                  ( pdMS_TO_TICKS( 20 ) )



/*
Maximum number of Modbus functions codes the protocol stack should support.
The maximum number of supported Modbus functions must be greater than
the sum of all enabled functions in this file and custom function
handlers. If set to small adding more functions will fail.
*/
#define MB_FUNC_HANDLERS_MAX                    ( 16 )

/*
Number of bytes which should be allocated for the <em>Report Slave ID </em>command.

This number limits the maximum size of the additional segment in the
report slave id function. See eMBSetSlaveID(  ) for more information on
how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
is set to <code>1</code>.
*/
#define MB_FUNC_OTHER_REP_SLAVEID_BUF           ( 32 )

/*If the <em>Report Slave ID</em> function should be enabled. */
#define MB_FUNC_OTHER_REP_SLAVEID_ENABLED       (  CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT )

/*If the <em>Read Input Registers</em> function should be enabled. */
#define MB_FUNC_READ_INPUT_ENABLED              (  1 )

/*If the <em>Read Holding Registers</em> function should be enabled. */
#define MB_FUNC_READ_HOLDING_ENABLED            (  1 )

/*If the <em>Write Single Register</em> function should be enabled. */
#define MB_FUNC_WRITE_HOLDING_ENABLED           (  1 )

/*If the <em>Write Multiple registers</em> function should be enabled. */
#define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED  (  1 )

/*!If the <em>Read Coils</em> function should be enabled. */
#define MB_FUNC_READ_COILS_ENABLED              (  1 )

/*If the <em>Write Coils</em> function should be enabled. */
#define MB_FUNC_WRITE_COIL_ENABLED              (  1 )

/*If the <em>Write Multiple Coils</em> function should be enabled. */
#define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED    (  1 )

/*If the <em>Read Discrete Inputs</em> function should be enabled. */
#define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED    (  1 )

/*If the <em>Read/Write Multiple Registers</em> function should be enabled. */
#define MB_FUNC_READWRITE_HOLDING_ENABLED       (  1 )

/*Check the option to place timer handler into IRAM */
#define MB_PORT_TIMER_ISR_IN_IRAM               (  CONFIG_FMB_TIMER_USE_ISR_DISPATCH_METHOD )


#ifdef __cplusplus
}
#endif


/*If master send a broadcast frame, the master will wait time of convert to delay,
then master can send other frame */
#define MB_MASTER_DELAY_MS_CONVERT              ( 200 )
/*If master send a frame which is not broadcast,the master will wait sometime for slave.
And if slave is not respond in this time,the master will process this timeout error.
Then master can send other frame */
#define MB_MASTER_TIMEOUT_MS_RESPOND            ( 8000 )
/*brief The total slaves in Modbus Master system.
note : The slave ID must be continuous from 1.*/
#define MB_MASTER_TOTAL_SLAVE_NUM               ( 247 )



